// ++++++++++++++++++++++++++++++++++++++++
// 《零基础Go语言算法实战》源码
// ++++++++++++++++++++++++++++++++++++++++
// Author:廖显东（ShirDon）
// Blog:https://www.shirdon.com/
// Gitee:https://gitee.com/shirdonl/goAlgorithms.git
// Buy link :https://item.jd.com/14101229.html
// ++++++++++++++++++++++++++++++++++++++++

package main

import "fmt"

func visitAllRooms(array [][]int) bool {
	visited := make([]bool, len(array))
	dfs(0, array, visited)
	ret := true
	for _, v := range visited {
		ret = ret && v
	}
	return ret
}

func dfs(index int, array [][]int, visited []bool) {
	if visited[index] {
		return
	}
	visited[index] = true
	for _, v := range array[index] {
		dfs(v, array, visited)
	}
}

func main() {
	array := [][]int{{1, 3}, {3, 0, 1}, {2}, {0}}
	res := visitAllRooms(array)
	fmt.Println(res)
}

//$ go run interview5-4.go
//false
